package com.gzhu.knowledgeAdmin.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.gzhu.knowledgeAdmin.common.vo.CompanyVo;
import com.gzhu.knowledgeAdmin.entity.PageBean;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;


import com.gzhu.knowledgeAdmin.dao.GsxxDao;
import com.gzhu.knowledgeAdmin.entity.Gsxx;
import com.gzhu.knowledgeAdmin.service.GsxxService;

import javax.annotation.Resource;


@Service("gsxxService")
public class GsxxServiceImpl extends ServiceImpl<GsxxDao, Gsxx> implements GsxxService {

    @Autowired
    private GsxxDao gsxxDao;


    @Override
    public List<CompanyVo> getAllCompany() {

        List<Gsxx> gsxxList = baseMapper.selectList(new QueryWrapper<>());
        return gsxxList.stream().map(item -> {
            CompanyVo companyVo = new CompanyVo();
            companyVo.setName(item.getGsmc());
            companyVo.setId(item.getGsid());
            return companyVo;
        }).collect(Collectors.toList());
    }

    @Override
    public PageBean<Gsxx> selectAllGsxx(Integer pageNum,Integer pageSize,@Param("gsid")String gsid) {

        PageBean<Gsxx> pageBean = new PageBean<>();
        PageHelper.startPage(pageNum,pageSize);

        List<Gsxx> list1=gsxxDao.selectAllGsxx(gsid);
        Page<Gsxx> page= (Page<Gsxx>) list1;

        pageBean.setTotal(page.getTotal());
        pageBean.setItems(page.getResult());

        return pageBean;
    }

    @Override
    public List<Gsxx> selecttest() {

        return gsxxDao.selecttest();
    }
}
